package 算法.leetcode.offer;

/**
 * @author lchenglong
 * @date 2022/4/28
 */
public class Offer44 {
    public int findNthDigit(int n) {
        // 记录n所在位数1,2,3,4...
        int b = 1;
        // 记录每个b位数的起始数字,1,10,100,1000...
        long start = 1;
        // 每个位所包含的数据量 1-9->9 10-100->90 100->1000 900
        long count = 9;
        while (count<n){
            n-=count;
            ++b;
            start*=10;
            count = b * start * 9;
        }
        long num = start + (n - 1) / b; // 2. 确定N所在的数字
        return Long.toString(num).charAt((n - 1) % b) - '0';
    }
}
